import React, { Component } from 'react';
import {View} from '@tarojs/components'
import GzhAuth from "../../../components/gzh-auth/gzh-auth"
import {GetRequest, vcmonitor} from "../../../utils/tools";
import {INVOICE_ORDER_TITLE_DETAIL} from "../../../constants/api";
import {http} from "../../../utils/http";
import './invoice.scss'

interface StateType {
  info: any
  headType: any
  setDefault: any
}

export default class Invoice extends Component {
  state: StateType = {
    info: {
      invoicetitle_name: '',
      invoicetitle_type: '',
      unit_id_number: '',
      remark: '',
      address: '',
      phone: '',
      bank: '',
      bank_account: ''
    }
  }

  async UNSAFE_componentWillMount() {
    vcmonitor(this)
    let {info} = this.state
    const data = await http.HGet(INVOICE_ORDER_TITLE_DETAIL, { id: Taro.getCurrentInstance().router.params.id || '' })
    info = this.jiaoji(info, data.data)
    this.setState({info})
  }

  jiaoji(a, b) {
    const c = {}
    for (const item in a) {
      if (b[item] !== undefined && b[item] !== null) {
        c[item] = b[item]
      } else {
        c[item] = a[item]
      }
    }
    return c
  }

  render() {
    const {info} = this.state
    return (
      <View className='Invoice-Information-order'>
        <GzhAuth />
        <View className='wrapper-invoice-detail'>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>发票类型</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.invoicetitle_type ? '企业' : '个人或事业单位' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>发票抬头</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.invoicetitle_name || '-' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>税号</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.unit_id_number || '-' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>卡户银行</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.bank || '-' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>银行账号</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.bank_account || '-' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>企业地址</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.address || '-' }</View>
          </View>
          <View className='wrapper-invoice-detail-items'>
            <View className='wrapper-invoice-detail-items-left'>企业电话</View>
            <View className='wrapper-invoice-detail-items-right'>{ info.phone || '-' }</View>
          </View>
        </View>
      </View>
    )
  }
}
